package com.yphone.ui.widget;

import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.zzkj.yunphone.R;

public class TopView extends FrameLayout {

    private String name;
    private TextView tv_name;
    private View iv_back;

    public TopView(@NonNull Context context) {
        this(context, null);
    }

    public TopView(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public TopView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(attrs);
        initData();
    }

    private void initData() {
        tv_name.setText(name);
    }

    private void initView(AttributeSet attrs) {
        TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.topView);
        name = array.getString(R.styleable.topView_viewName);
        View.inflate(getContext(),R.layout.top_view,this);
        tv_name = findViewById(R.id.tv_name);
        iv_back = findViewById(R.id.iv_back);
        iv_back.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ((Activity)getContext()).finish();
            }
        });
    }

    public void setName(String viewName){
        tv_name.setText(viewName);
    }
}
